--[[
FilePath: \Lua\View\UISealCrystal\UISealCrystalTips.lua
封印水晶活动阶段奖励预览
--]]

require 'View/UIBase/UIBase'

UISealCrystalTips = UIBase.New(PanelNames.UISealCrystalTips)
local _M = UISealCrystalTips

_M.hasInit = false

function _M.Init(func, id, serverRewards, rewardsNum)
    _M.activeId = id
    _M.serverRewards = serverRewards
    _M.rewardsNum = rewardsNum
    UIBase.Init(_M, func)
end

function _M:OnCreate()
    if not _M.hasInit then
        self:RegisterOnClick(self:GetChild("btnClose"), self.OnBack)
        self.txtTips = self:GetChild("txttips")
        self.closeTips = self:GetChild("closeTips")
        self.tipsList = self:GetChild("tipsList")

        self.tipsList.itemRenderer = self.refreshItem;

        _M.hasInit = true
        self:addEvent()
    end

    self:init();
end

function _M:addEvent()

end

function _M:removeEvent()

end

function _M:init()
    self.txtTips.text = getLanguage("ActivityDesc1100105");
    local sealCrystalCfg = G.dataTable["t_sealcrystal"];
    self.sealCrystal = {}
    for k, v in pairs(sealCrystalCfg) do
        table.insert(self.sealCrystal, v)
    end
    table.sort(self.sealCrystal, function(a, b)
        return a.f_CrystalBoxID < b.f_CrystalBoxID
    end)

    self.tipsList.numItems = #self.sealCrystal
end

function _M.refreshItem(index, obj)
    local itemIndex = index + 1;
    local itemList = obj:GetChild("itemList")
    local title = obj:GetChild("title")
    local status = obj:GetController("status")
    status.selectedIndex = 1
    if _M.serverRewards == nil or _M.serverRewards[itemIndex] == nil then
        status.selectedIndex = 0
        title.text = string.format(getLanguage("ActivityDesc1100106"), _M.rewardsNum, _M.sealCrystal[itemIndex].f_RewardCount)
    end
    logicMgr.CostManager.RefreshItemList(itemList, decodeJsonStrToTabel(_M.sealCrystal[itemIndex].f_CrystalReward))
end

-- 显示
function _M:OnEnable()

end

-- 隐藏
function _M:OnDisable()

end

-- 卸载
function _M:OnDestroy()
    self:removeEvent();
end

return _M;